<?php
/**
 * Template Name: List Subpages
 *
 * 
 *
 * @package Stencil
 * @subpackage Template
 */

get_header(); // Loads the header.php template. ?>

	<?php do_atomic( 'before_content' ); // stencil_before_content ?>

	<div id="content">

		<?php do_atomic( 'open_content' ); // stencil_open_content ?>

		<div class="hfeed">

			<?php if ( have_posts() ) : ?>

				<?php while ( have_posts() ) : the_post(); ?>

					<?php do_atomic( 'before_entry' ); // stencil_before_entry ?>

					<div id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">

						<?php do_atomic( 'open_entry' ); // stencil_open_entry ?>

						<?php echo apply_atomic_shortcode( 'entry_title', '[entry-title]' ); ?>
                        
                        <?php do_atomic( 'before_entry_content' ); // stencil_before_entry_content ?>

						<div class="entry-content">
							<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', hybrid_get_textdomain() ) ); ?>
							<?php wp_link_pages( array( 'before' => '<p class="page-links">' . __( 'Pages:', hybrid_get_textdomain() ), 'after' => '</p>' ) ); ?>
						</div><!-- .entry-content -->

						<?php echo apply_atomic_shortcode( 'entry_meta', '<div class="entry-meta">[entry-edit-link]</div>' ); ?>

						<?php do_atomic( 'close_entry' ); // stencil_close_entry ?>

					</div><!-- .hentry -->

					<?php do_atomic( 'after_entry' ); // stencil_after_entry ?>
                    
                    <?php $mypages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
										
						$count = 0;
						foreach($mypages as $page)
						{		
							$loop = new WP_Query( array( 'image_scan'=> true, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'showposts' => 1, 'orderby' => 'parent' ) );
							$content = $page->post_content;

							if(!$content)
								continue;
							
							$count++;	
							$content = apply_filters('the_excerpt', $content);	
							$thumb = get_the_post_thumbnail($page->ID, 'thumbnail', array('class' => 'rm_img', 'title'=> trim(strip_tags( $page->post_title) ) ) );
							
						?>
                     <div class="page-list clear">
					<h2><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h2>
                     <?php if($thumb != '') {
					 		echo '<div class="img_loader thumbnail add_preloader">
                   			 	  <a href="' . get_page_link($page->ID) . '" class="load_img">'. $thumb.'</a>
                    			  </div>';
                            } else {} ?>
					<div class="entry-content">
					<?php echo string_limit_words(strip_shortcodes( $content ),40); ?>
                    <div><a class="button" href="<?php echo get_page_link($page->ID); ?>">View Page</a></div>
                    </div>
                    </div>
				<?php 	} ?>

					<?php get_sidebar( 'after-singular' ); // Loads the sidebar-after-singular.php template. ?>

					<?php do_atomic( 'after_singular' ); // stencil_after_singular ?>

					<?php comments_template( '/comments.php', true ); // Loads the comments.php template. ?>

				<?php endwhile; ?>

			<?php endif; ?>
            

		</div><!-- .hfeed -->

		<?php do_atomic( 'close_content' ); // stencil_close_content ?>

	</div><!-- #content -->

	<?php do_atomic( 'after_content' ); // stencil_after_content ?>

<?php get_footer(); // Loads the footer.php template. ?>